package com.tanhua.server.controller;


import com.tanhua.model.dto.RecommendUserDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;

    /*今日佳人*/
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    /*推荐朋友列表*/
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserDto dto) {
        PageResult pr = tanhuaService.recommendation(dto);
        return ResponseEntity.ok(pr);
    }

    /*查看佳人信息*/
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity findPersonalInfo(@PathVariable("id") Long userId) {
        TodayBest todayBest = tanhuaService.findPersonalInfo(userId);
        return ResponseEntity.ok(todayBest);
    }

    /*查看陌生人问题*/
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId) {
        String questions = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(questions);
    }

    /*回复陌生人问题*/
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyStrangerQuestions(@RequestBody Map map) {
        String obj = map.get("userId").toString();
        Long userId = Long.valueOf(obj);
        String reply = map.get("reply").toString();
        tanhuaService.replyStrangerQuestions(userId, reply);
        return ResponseEntity.ok(null);
    }

    /*探花-左滑右滑*/
    @GetMapping("/cards")
    public ResponseEntity cards() {
        List<TodayBest> list = this.tanhuaService.queryCardsList();
        return ResponseEntity.ok(list);
    }

    /*探花-喜欢*/
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") Long likeUserId) {
        tanhuaService.love(likeUserId);
        return ResponseEntity.ok(null);
    }

    /*探花-不喜欢*/
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") Long likeUserId) {
        tanhuaService.unlove(likeUserId);
        return ResponseEntity.ok(null);
    }

    /*搜附近*/
    @GetMapping("/search")
    public ResponseEntity searchNearUser(String gender,
                                         @RequestParam(defaultValue = "2000") String distance) {
        List<NearUserVo> vo = tanhuaService.searchNearUser(gender, distance);
        return ResponseEntity.ok(vo);

    }

}
